package com.lbd.gulimall.search.app;

import com.lbd.gulimall.search.service.ElasticSearchService;
import com.lbd.gulimall.search.vo.SearchParam;
import com.lbd.gulimall.search.vo.SearchResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: linbd
 * @Description:
 * @Date: 2023/2/24 1:47
 */
@Controller
public class SearchIndexController {
    @Autowired
    private ElasticSearchService elasticSearchService;

    @RequestMapping("/list.html")
    public String toSearchIndex(SearchParam param, Model model, HttpServletRequest request) {
        String queryString = request.getQueryString();
        param.set_qStr(queryString);
        SearchResult result = elasticSearchService.search(param);
        if (result == null) {
            model.addAttribute("error","接口异常");
        }else {
            model.addAttribute("searchResult",result);
        }
        return "list";
    }


}
